<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客系统页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js"></script>
    <script src="./js/app.js"></script>

</head>
    <body>
    <!-- 背景 -->
    <div class="nav">
            <!-- 头像 -->
        <img class src="./image/cat.webp" alt="头像">
        <div class="title">
            我的博客系统
        </div>
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>

    </div>
    <!-- 页面的主体部分 -->
    <div class="container">
        <!-- 左侧部分 -->
        <div class="container-left">
            <div class="card">

            <img src="./image/dog.jpg">
            <h3></h3>
            <a href="https://blog.csdn.net/xiaoyubuhuiqiche?spm=1000.2115.3001.5343" target="_blank">gitee</a>
                <div class="conter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="conter">
                    <span class="article"></span>
                    <span class="sort"></span>
                </div>
            </div>
        </div>

        <!-- 右侧部分 -->
        <div class="container-right">

        </div>
    </div>
    <script>
        function getBlog(){
            $.ajax({
                type:"get",
                url:"blog",
                success:function(body){
                    //在这里主要写接收到了博客列表之后如何处理的数据
                    let containerDiv = document.querySelector('.container-right');
                    for (let num of body) {
                        
                        let blogDiv = document.createElement('div');
                        blogDiv.className = 'blog';
                        
                        let title = num.title;//博客标题
                        let userId = num.userId;//用户id
                        let postTime = num.postTime;//发布时间
                        let content = num.content;//博客正文

                        let titleDiv = document.createElement('div');
                        titleDiv.className = 'title';
                        titleDiv.innerHTML = title;
                        blogDiv.appendChild(titleDiv);

                        let timeDiv = document.createElement('div');
                        timeDiv.className = 'date';
                        timeDiv.innerHTML = postTime;
                        blogDiv.appendChild(timeDiv);

                        let contentDiv = document.createElement('div');
                        contentDiv.className = 'desc';
                        contentDiv.innerHTML = content;
                        blogDiv.appendChild(contentDiv);


                        let a = document.createElement('a');
                        a.href = 'blog_detail.html?blogId='+num.blogId;
                        a.innerHTML = '查看全文';
                        blogDiv.appendChild(a);

                        containerDiv.appendChild(blogDiv);

                    }
                }
            });
        }
        getBlog();
        checkLogin();
        getUser();

    </script>
    </body>
</html>
